package com.qf.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.Users;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 千锋健哥
 */
public interface UserMapper extends BaseMapper<Users> {

    /**
     * 根据用户id, 获取角色列表
     * @param id
     * @return
     */
    @Select("select c.`name` " +
            "from sys_user a  " +
            "left join sys_user_role b on a.id = b.user_id " +
            "left join sys_role c on c.id =  b.role_id " +
            "where a.id=#{id}")
    public List<String> findRoleListByUserId(@Param("id") Long id);

    /**
     * 根据用户id查询菜单列表
     * @param id
     * @return
     */
    @Select("select e.perms " +
            "from sys_user a  " +
            "left join sys_user_role b on a.id = b.user_id " +
            "left join sys_role c on c.id =  b.role_id " +
            "left join sys_role_menu d on d.role_id = c.id " +
            "left join sys_menu e on e.id = d.menu_id " +
            "where a.id=#{id}")
    public List<String> findMenuListByUserId(@Param("id") Long id);
}
